<template>
  <el-dialog
    title="升级包地址"
    :visible.sync="dialogVisible"
    width="600px"
  >
    <div>{{ this.packageUrl }}</div>
    <span
      slot="footer"
      class="dialog-footer"
    >
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button
        type="primary"
        @click="copy"
        :loading="btnLoading"
      >复制</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { Message } from 'element-ui';

export default {
  data() {
    this.formLabelWidth = '120px';
    return {
      packageUrl: '',
      dialogVisible: false,
      btnLoading: false
    };
  },
  methods: {
    showUrlDialog(url) {
      this.packageUrl = url;
      this.dialogVisible = true;
    },
    copy() {
      const input = document.createElement('input');
      document.body.appendChild(input);
      input.setAttribute('value', this.packageUrl);
      input.select();
      if (document.execCommand('copy')) {
        document.execCommand('copy');
      }
      document.body.removeChild(input);
      Message.success('复制成功');
      this.dialogVisible = false;
    }
  }
};
</script>

<style lang="scss" scoped>
.input {
  width: 300px;
}
</style>
